package com.myself.storm_test;

import backtype.storm.Config;
import backtype.storm.LocalCluster;
import backtype.storm.StormSubmitter;
import backtype.storm.topology.TopologyBuilder;

public class WordCountTopology {

	public WordCountTopology(String server) throws Exception {
		TopologyBuilder builder = new TopologyBuilder();

		new WordCountBuilder(builder);
		Config conf = new Config();
		conf.setDebug(true);
		if (server != null && !"".equals(server)) {
			// conf.put(Config.NIMBUS_HOST, server);
			// conf.setNumWorkers(2);
			// StormSubmitter.submitTopologyWithProgressBar(TOPOLOGYID, conf,
			// builder.createTopology());
		} else {
			// 本地测试
			conf.setMaxTaskParallelism(3);
			LocalCluster cluster = new LocalCluster();
			cluster.submitTopology("word-count", conf, builder.createTopology());
		}
	}

	public static void main(String[] args) throws Exception {

		try {
			String result = null;
			if (args != null && args.length > 0) {
				result = args[0];
			}
			new WordCountTopology(result);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
